A = [8, 1, 5, 2, 6]

i_max = 0
j_max = 0

res = 0

for j in range(0, len(A)):
    res = max(res, i_max + A[j] - j)
    i_max = max(A[j] + j, i_max)

print(res)
